package com.shop.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.common.core.domain.Result;
import com.shop.coupon.domain.SkuFullReduction;
import com.shop.coupon.mapper.SkuFullReductionMapper;
import com.shop.coupon.service.SkuFullReductionService;
import org.springframework.stereotype.Service;

@Service
public class SkuFullReductionServiceImpl extends ServiceImpl<SkuFullReductionMapper,SkuFullReduction> implements SkuFullReductionService {

    private final SkuFullReductionMapper skuFullReductionMapper;

    public SkuFullReductionServiceImpl(SkuFullReductionMapper skuFullReductionMapper) {
        this.skuFullReductionMapper = skuFullReductionMapper;
    }

    /**
     * skuId商品专属满减优惠券
     * @param pageNum
     * @return
     */
    @Override
    public Result skuIdFull(Integer pageNum , Integer pageSize) {
        QueryWrapper<SkuFullReduction> queryWrapper = new QueryWrapper<>();
        Page<SkuFullReduction> reductionPage = new Page<>();
        Page<SkuFullReduction> selectPage = skuFullReductionMapper.selectPage(reductionPage, queryWrapper);
        return Result.success(selectPage);
    }

    /**
     * sku商品专属满减优惠券规则修改
     * @param skuFullReduction
     * @return
     */
    @Override
    public Result skuFullUpdateRule(SkuFullReduction skuFullReduction) {
        int skuFullUpdateRule = baseMapper.updateById(skuFullReduction);
        return Result.success("修改成功"+skuFullUpdateRule);
    }

    /**
     * sku商品专属满减优惠券添加
     * @param skuFullReduction
     * @return
     */
    @Override
    public Result skuFullInsert(SkuFullReduction skuFullReduction) {
        int skuFullInsert = baseMapper.insert(skuFullReduction);
        return Result.success("专属商品优惠券添加成功"+skuFullInsert);
    }

    @Override
    public Result<SkuFullReduction> getSkuFull(Long id) {
        SkuFullReduction skuFullReduction = skuFullReductionMapper.selectById(id);
        return Result.success(skuFullReduction);
    }

    @Override
    public Result skuFullDelete(Long id) {
        int byId = baseMapper.deleteById(id);
        return Result.success(byId);
    }
}
